<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/md5.asp"-->
<!--#include file="../common/admin.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>main</title>
<link href="../css/style.css" rel="stylesheet" type="text/css"/>
<style>body {background-color: #eaece1;}</style>
</head>

<body>
<div class="main">
  <div class="main-title">类目</div>
  <div class="main-content">
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <tr>
    <td colspan="6">
    <form name="form" method="post" action="">
    <input name="title" type="text" class="input" id="title" value="库房" maxlength="50" />
    <input name="shelf" type="text" class="input" id="shelf" value="货架数量" maxlength="50" />
    <input name="seat" type="text" class="input" id="seat" value="单个货架位置数量" maxlength="50" />
    <input type="submit" name="button" id="button" value="添加" />
    </form>
    </td>
    </tr>
    </table>
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <tr>
    <td bgcolor="#FFFFFF"><strong>库房</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>货架数量</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>单个货架位置数量</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>删除</strong></td>
    </tr>
     <%
					  set rsu=server.CreateObject("adodb.recordset")
					  sql="select * from Storeroom"
					  rsu.open sql,conn,1,3
					  if not rsu.eof then
					  do while not rsu.eof
					  %>
  <tr>
    <td bgcolor="#FFFFFF"><%=rsu("title")%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rsu("Shelf")%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rsu("Seat")%></td>
    <td align="center" bgcolor="#FFFFFF"><a href="?del=<%=rsu("id")%>">删除</a></td>
    </tr>
    <%
					  rsu.movenext
					  loop
					  rsu.close
					  set rsu=nothing
					  end if		 
					  %>
  
  </table>
</div>
</div>
</body>
</html>
<%
if request.Form("button")="添加" then

	title=request.Form("title")
	shelf=request.Form("shelf")
	seat=request.Form("seat")
    if title="" or shelf="" or seat="" then
		response.write"<script>alert('库房、货架数量、单个货架位置数量不能为空');</script>"
		response.write"<script>window.history.back(-1);</script>"
		response.end
	end if
    if isnumeric(shelf)=false then shelf=16
	if isnumeric(seat)=false then seat=16
    
	'库房写入
	set rsu=server.createobject("adodb.recordset")
	sql="select * from Storeroom"
	rsu.open sql,conn,1,3
	rsu.addnew
	rsu("title")=title
	rsu("shelf")=shelf
	rsu("seat")=seat
	rsu.update
	temp = rsu.bookmark 
    rsu.bookmark = temp 
    ID=rsu("ID")
	rsu.close
	set rsu=nothing
	
	'货架写入
	for i=1 to shelf
	set rsu=server.createobject("adodb.recordset")
	sql="select * from shelf"
	rsu.open sql,conn,1,3
	rsu.addnew
	rsu("fid")=ID
	rsu("Number")=i
	rsu.update
	tempx = rsu.bookmark 
    rsu.bookmark = tempx
    fid=rsu("ID")
	rsu.close
	set rsu=nothing
	
	'位置写入
	for ii=1 to seat
	set rsu=server.createobject("adodb.recordset")
	sql="select * from seat"
	rsu.open sql,conn,1,3
	rsu.addnew
	rsu("kid")=id
	rsu("fid")=fid
	rsu("Number")=ii
	rsu.update
	rsu.close
	set rsu=nothing
	next
	next
	response.write"<script language=JavaScript>{window.alert('添加成功！');window.location.href='type.asp';}</script>"

elseif request.QueryString("del")<>"" then
    conn.execute("delete from Seat where fid in (select id from Shelf where fid="&request.QueryString("del")&")")
	conn.execute("delete from Shelf where fid="&request.QueryString("del")&"")
	conn.execute("delete from Storeroom where id="&request.QueryString("del")&"")
	response.Redirect "type.asp"
end if
%>